﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Bootstrap.MVC.Common;
using Bootstrap.MVC.Infrastructure.Html;
using Bootstrap.MVC.Utils;

namespace Bootstrap.MVC.Widgets
{
    public class DropDownMenuHtmlGenerator : HtmlGeneratorBindableBase<IDropDownMenuModel>
    {
        public DropDownMenuHtmlGenerator(IDropDownMenuModel model) : base(model) { }



        //    <ul class="dropdown-menu">
        //        <li><a href="#">Action</a></li>
        //        <li><a href="#">Another action</a></li>
        //        <li><a href="#">Something else here</a></li>
        //        <li class="divider"></li>
        //        <li><a href="#">Separated link</a></li>
        //    </ul>
        public override HtmlTagBuilder AsHtmlBuilder()
        {
            var dropdownTag = new HtmlTagBuilder("ul", Model.Attributes)
                                                .AddClass("dropdown-menu")
                                                .Attr(new { role = "menu", aria_labelledby = "dropdownMenu"});

            if (Model.Align == LeftOrRight.Right)
                dropdownTag.AddClass("pull-right");


            foreach (var item in Model.Items)
            {
                dropdownTag.Append(new DropDownItemHtmlGenerator(item).AsHtmlBuilder());
            }

            return Model.DropUp ? new HtmlTagBuilder("div").AddClass("dropup").Append(dropdownTag)
                                : dropdownTag;
                                
        }

        public override string Render()
        {
            return AsHtmlBuilder().Render();
        }


        

    }
}
